package chrome.entity;

import chrome.Interface.SerializeObj;
import com.alibaba.fastjson.JSONObject;
import commons.entity.NativeCp;
import commons.util.GameUtil;
import commons.util.ProcessDealUtil;
import fgoScript.entity.PointColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Chrome implements SerializeObj {
    private static final Logger LOGGER = LogManager.getLogger(Chrome.class);

    public static Chrome chrome;
    public static Chrome getInstance(){
        if (chrome == null) {
            String filepath = NativeCp.getUserDir() + "/config/CHROME/Chrome.json";
            chrome = JSONObject.parseObject(GameUtil.getJsonString(filepath), Chrome.class);

        }
        return chrome;
    }

    private String chromeExePath;
    private List<PointColor> signatureList;
    private List<PointColor> zeroCheckPoints;
    private int delaySeconds;
    private PointColor needSignPoint;

    public int getDelaySeconds() {
        return delaySeconds;
    }

    public void setDelaySeconds(int delaySeconds) {
        this.delaySeconds = delaySeconds;
    }

    public String getChromeExePath() {
        return chromeExePath;
    }

    public void setChromeExePath(String chromeExePath) {
        this.chromeExePath = chromeExePath;
    }

    public List<PointColor> getZeroCheckPoints() {
        return zeroCheckPoints;
    }

    public void setZeroCheckPoints(List<PointColor> zeroCheckPoints) {
        this.zeroCheckPoints = zeroCheckPoints;
    }

    public List<PointColor> getSignatureList() {
        return signatureList;
    }

    public void setSignatureList(List<PointColor> signatureList) {
        this.signatureList = signatureList;
    }

    public PointColor getNeedSignPoint() {
        return needSignPoint;
    }

    public void setNeedSignPoint(PointColor needSignPoint) {
        this.needSignPoint = needSignPoint;
    }

    public void startChrome(){
        try {
            ProcessDealUtil.executeCmd(this.getChromeExePath(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public Object GenerateJsonObj() {
        Chrome c = new Chrome();
        List<PointColor> pcList= new ArrayList<>();
        PointColor pc;

        for (int i = 0; i < 4; i++) {
            pc = new PointColor();
            pc.setColor(new Color(0,0,0));
            pc.setPoint(new Point());
            pcList.add(pc);
        }

        c.setChromeExePath("\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\"");
        c.setSignatureList(pcList);
        c.setDelaySeconds(2);
        return c;
    }

    public static void main(String[] args) {
        try {
            ProcessDealUtil.killProc("chrome.exe");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
